package com.oneday.ashop.core.base.init;

import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

/**
 * User:bob.yang
 * Date 2015/8/31 0031
 */
public class HttpClientTest {

    public static void main(String[] args) {
        //获得一个默认的HttpClient客户端
        RequestConfig defaultRequestConfig = RequestConfig.custom()
                .setSocketTimeout(5000)
                .setConnectTimeout(5000)
                .setConnectionRequestTimeout(5000)
                .setCookieSpec(CookieSpecs.STANDARD_STRICT)
                .build();
        CloseableHttpClient httpClient = HttpClients.custom()
                .setDefaultRequestConfig(defaultRequestConfig)
                .build();

        String uri = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc4dbd4dd2ed6dea2&redirect_uri=http%3A%2F%2Feku001.cn%2Fwx_reg_page.htm%3Fdid%3D93%26comeFrom%3D1%26sourceOpenid%3Dnull&response_type=code&scope=snsapi_base&state=123&&connect_redirect=1#wechat_redirect";
        //模拟浏览器
        HttpGet httpGet =   new HttpGet(uri);
        //发送请求
        CloseableHttpResponse response = null;
        try {
            response = httpClient.execute(httpGet);
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            System.out.println(EntityUtils.toString(response.getEntity()));
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            response.close();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
